package com.b.a.b.crossword.domain.impl;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.b.a.b.crossword.domain.WordSource;

public  abstract class  AbstractSourceWord implements WordSource{
	private   List<String> data;
   private int longueur;
	public List<String> getData() {
		return data;
	}

	public void setData(List<String> data) {
		
		this.data = sort(data);
		longueur=data.size();
	}

	private List<String> sort(List<String> data) {
		// TODO Auto-generated method stub
		Collections.sort(data, new Comparator<String>() {

			@Override
			public int compare(String o1, String o2) {
				// TODO Auto-generated method stub
				 Integer oneL=new Integer(o1.length());
				 Integer twoL=new Integer(o2.length());
				 if(oneL<twoL) return 1;
				 if(oneL>twoL) return -1;
				 return 0;
			}
		});
		return data;
	}

	@Override
	public List<String> getWordList() {
		// TODO Auto-generated method stub
		return data;
	}
	@Override
	public String get(int index){
		return data.get(index);
	}
	@Override
	public int size() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public String nextWord() {
		// TODO Auto-generated method stub
		synchronized (data) {
			if(data.isEmpty())return null;
			String res=data.get(0);
			data.remove(0);
			return res;
		}
		 
	}

	@Override
	public Boolean hasMoreElement() {
		// TODO Auto-generated method stub
		return !data.isEmpty();
	}
	@Override
	public String first() {
		// TODO Auto-generated method stub
		System.out.println(data);
		String res = data.get(0);
		data.remove(0);
		return res;
	}
	 
}
